package main

import "fmt"

func main() {
	//demoArray()
	traverseArray()
}

func demoArray() {
	// 输出
	// 0 0 0 0 0
	// 0 0 1 0 0
	// 0 1 2 3 5
	// 0 4 6 7 5
	// ---------------------------------------------
	// 定义并赋值一
	//var arr [4][5]int
	//arr[1][2] = 1
	//arr[2][1] = 1
	//arr[2][2] = 2
	//arr[2][3] = 3
	//arr[2][4] = 5
	//arr[3][1] = 4
	//arr[3][2] = 6
	//arr[3][3] = 7
	//arr[3][4] = 5
	// ----------------------------------------------
	// 定义并赋值二
	var arr [4][5]int = [4][5]int{{0, 0, 0, 0, 0}, {0, 0, 1, 0, 0}, {0, 1, 2, 3, 4}, {0, 4, 6, 7, 5}}
	for i := 0; i < len(arr); i++ {
		for j := 0; j < len(arr[i]); j++ {
			fmt.Printf("%d ", arr[i][j])
		}
		fmt.Printf("\n")
	}
	fmt.Printf("arr[0]的地址%p\n", &arr[0])
	fmt.Printf("arr[0][0]的地址%p\n", &arr[0][0])
	fmt.Printf("arr[1]的地址%p\n", &arr[1])
	fmt.Printf("arr[1][0]的地址%p\n", &arr[1][0])
}

func traverseArray() {
	var arr [2][3]int = [2][3]int{{1, 2, 3}, {6, 5, 4}}
	// for
	for i := 0; i < len(arr); i++ {
		for j := 0; j < len(arr[i]); j++ {
			fmt.Printf("%v\t", arr[i][j])
		}
		fmt.Println()
	}
	fmt.Println()
	fmt.Println()

	// for range
	for _, v1 := range arr {
		for _, v2 := range v1 {
			fmt.Printf("%v\t", v2)
		}
		fmt.Println()
	}
}
